package com.xhs.controller;

import com.xhs.dto.request.*;
import com.xhs.entity.MeCompanyEntity;
import com.xhs.message.ReturnResult;
import com.xhs.service.MeBeneficiaryService;
import com.xhs.service.MeCompanyService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * @desc: 企业信息相关接口
 * @projectName: mybatis-flex-demo
 * @author: xhs
 * @date: 2023-8-2 23:26
 * @version: JDK 1.8
 */
@Validated
@RestController
@RequestMapping("/companyInfo")
public class CompanyController {
    @Resource
    private MeCompanyService companyService;
    @Resource
    private MeBeneficiaryService beneficiaryService;

    /**
     * 分页查询客户信息
     *
     * @param pageParams 查询条件
     * @return ReturnResult
     */
    @PostMapping("/getCompanyInfoPage")
    public ReturnResult<Object> getCompanyInfoPage(@Valid @RequestBody CompanyPageParams pageParams) {
        return companyService.getCompanyInfoPage(pageParams);
    }

    /**
     * 查询企业的受益人
     *
     * @param pageParams 查询条件
     * @return ReturnResult
     */
    @PostMapping("/getCompanyBeneficiary")
    public ReturnResult<Object> getCompanyBeneficiary(@Valid @RequestBody CompanyPageParams pageParams) {
        return companyService.getCompanyBeneficiary(pageParams);
    }

    /**
     * 查询企业受益人信息
     *
     * @param params 查询条件
     * @return ReturnResult<Object>
     */
    @PostMapping("/getBeneficiary")
    public ReturnResult<Object> getBeneficiary(@Valid @RequestBody CompanyParams params) {
        return beneficiaryService.getBeneficiary(params);
    }

    /**
     * 新增企业
     *
     * @param params 参数
     * @return ReturnResult<Object>
     */
    @PostMapping("/addCompany")
    public ReturnResult<Object> addCompany(@Valid @RequestBody CompanyAddParams params) {
        return companyService.addCompany(params);
    }

    /**
     * 删除企业
     *
     * @param paramList 入参
     * @return ReturnResult<String>
     */
    @PostMapping("/delCompany")
    public ReturnResult<String> delCompany(@Valid @RequestBody @NotEmpty(message = "集合不能为空") List<DelCompanyParam> paramList) {
        return companyService.delCompany(paramList);
    }

    /**
     * 修改企业
     *
     * @param param 入参
     * @return ReturnResult<String>
     */
    @PostMapping("/updateCompany")
    public ReturnResult<String> updateCompany(@Valid @RequestBody CompanyEditParams param) {
        return companyService.updateCompany(param);
    }

    /**
     * 根据企业ID查询企业数据
     *
     * @param guId 入参
     * @return ReturnResult<MeCompanyEntity>
     */
    @GetMapping("/getCompany")
    public ReturnResult<MeCompanyEntity> getCompany(String guId) {
        return companyService.getCompany(guId);
    }
}
